﻿@model FutureApp.Roles.Dto.GetRoleUsersOutput

@section Scripts{
    <script>
        !function ($) {
            var $$$ = function () {
                this.$box = $('.box');
                this.$form = $('form');
                this.service = abp.services.app.role;
                this.localize = abp.localization.localize;
            };
            $$$.prototype = {
                init: function () {
                    this.formSubmit();
                    this.binding();
                },
                formSubmit: function () {
                    this.$form.submit(function (e) {
                        e.preventDefault();
                    });
                },
                binding: function () {
                    var self = this;
                    self.$box.on("click", '.btn', function (e) {
                        e.preventDefault();

                        var $sender = $(e.currentTarget);
                        var action = $.trim($sender.data("action"));
                        switch (action) {
                            case "submit":
                                self.submit();
                                break;
                        }
                    });
                },
                submit: function () {
                    var self = this;
                    abp.ui.setBusy(self.$box);
                    var data = self.$form.serializeFormToObject();
                    self.service.updateRoleUsers(data)
                        .done(function () {
                            abp.message.success(self.localize("UserAuthorizationSucceed"))
                                .done(function () { location.href = "@Url.Action("list")"; });
                        })
                        .always(function () {
                            abp.ui.clearBusy(self.$box);
                        });
                }
            };

            $(function () { (new $$$()).init(); });
        }(jQuery);
    </script>
}
<ul class="content-nav">
    <li>
        <a href="@Url.Action("list")">@L("List")</a>
    </li>
    <li>
        <a href="@Url.Action("add")">@L("Add")</a>
    </li>
    <li class="active">
        <a href="javascript:;">@L("UserAuthorization")【@this.Model.Role.Name】</a>
    </li>
</ul>
<div class="box box-success box-edge-all" data-dock="true">
    <form role="form" class="col-xs-10">
        <div class="box-body">
            <input type="hidden" name="RoleId" value="@this.Model.Role.Id" />
            <div class="form-group">
                <label>@L("RoleCode")</label>
                <div class="form-control">@this.Model.Role.Name</div>
            </div>
            <div class="form-group">
                <label>@L("RoleName")</label>
                <div class="form-control">@this.Model.Role.DisplayName</div>
            </div>

            <div class="form-group">
                <label>@L("User")</label>
                <div class="panel panel-default">
                    <div class="panel-body form-inline">
                        @foreach (var user in this.Model.Users.Items)
                        {
                            var check = this.Model.GrantedUsers.Items.Any(item => item.Id == user.Id);
                            <div class="input-group" style="padding-right:10px;padding-bottom:10px;">
                                <label class="input-group-addon input-group-check">
                                    @if (check)
                                    {
                                        <input name="GrantedUserIds[]" type="checkbox" value="@user.Id" checked>
                                    }
                                    else
                                    {
                                        <input name="GrantedUserIds[]" type="checkbox" value="@user.Id">
                                    }
                                    <i class="input-box"></i>
                                </label>
                                <div class="form-control">@(string.Format("{0}({1})", user.FullName, user.UserName))</div>
                            </div>
                        }
                    </div>
                </div>
            </div>
        </div>
        <div class="box-footer">
            <a class="btn btn-primary" href="javascript:;" data-action="submit">
                <i class="fa fa-check"></i>
                @L("Submit")
            </a>
        </div>
    </form>
</div>